import java.util.Scanner;

public class EncryptionDecryption {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入要加密的字符串: ");
        String originalText = scanner.nextLine();

        // 加密字符串
        String encryptedText = encrypt(originalText);
        System.out.println("加密后的字符串: " + encryptedText);

        // 解密字符串
        String decryptedText = decrypt(encryptedText);
        System.out.println("解密后的字符串: " + decryptedText);
    }

    public static String encrypt(String text) {
        StringBuilder encryptedText = new StringBuilder();
        for (char c : text.toCharArray()) {
            if (Character.isLetter(c)) {
                char offset = Character.isUpperCase(c) ? 'A' : 'a';
                char encryptedChar = (char) (offset + (c - offset + 1) % 26);
                encryptedText.append(encryptedChar);
            } else {
                encryptedText.append(c);
            }
        }
        return encryptedText.toString();
    }

    public static String decrypt(String text) {
        StringBuilder decryptedText = new StringBuilder();
        for (char c : text.toCharArray()) {
            if (Character.isLetter(c)) {
                char offset = Character.isUpperCase(c) ? 'A' : 'a';
                char decryptedChar = (char) (offset + (c - offset - 1 + 26) % 26);
                decryptedText.append(decryptedChar);
            } else {
                decryptedText.append(c);
            }
        }
        return decryptedText.toString();
    }
}
